
export default {
    components: {
    },
    data() {
        return {
            typeList: [
                {
                    label: "指标值 =",
                    value: "eq",
                    state: 1,

                },
                {
                    label: "指标值 <",
                    value: "lt",
                    state: 2,
                },
                {
                    label: "指标值 <=",
                    value: "lte",
                    state: 2,
                },
                {
                    label: "指标值 >",
                    value: "gt",
                    state: 3,
                },
                {
                    label: "指标值 >=",
                    value: "gte",
                    state: 3,
                },
                {
                    label: "指标值 < >",
                    value: "ltgt",
                    state: 4,
                },
                {
                    label: "指标值 <= >",
                    value: "ltegt",
                    state: 4,
                },
                {
                    label: "指标值 < >=",
                    value: "ltgte",
                    state: 4,
                },
                {
                    label: "指标值 <= >=",
                    value: "ltegte",
                    state: 4,
                },
            ],
            typeList2: [
                {
                    label: "分数 <",
                    value: "lt",
                    state: 2,
                },
                {
                    label: "分数 <=",
                    value: "lte",
                    state: 2,
                },
                {
                    label: "分数 >",
                    value: "gt",
                    state: 3,
                },
                {
                    label: "分数 >=",
                    value: "gte",
                    state: 3,
                },
                {
                    label: "分数 < >",
                    value: "ltgt",
                    state: 4,
                },
                {
                    label: "分数 <= >",
                    value: "ltegt",
                    state: 4,
                },
                {
                    label: "分数 < >=",
                    value: "ltgte",
                    state: 4,
                },
                {
                    label: "分数 <= >=",
                    value: "ltegte",
                    state: 4,
                },
            ],
            typeState: 0,
            typeList1: [
                {
                    label: "风险 <",
                    value: "lt",
                    state: 2,
                },
                {
                    label: "风险 <=",
                    value: "lte",
                    state: 2,
                },
                {
                    label: "风险 >",
                    value: "gt",
                    state: 3,
                },
                {
                    label: "风险 >=",
                    value: "gte",
                    state: 3,
                },
            ],
        }
    },
    watch: {
        typeState(val) {
            if (val) {
                this.$nextTick(() => {
                    let prop = ["value", "lower", "upper"];
                    this.$refs.form.clearValidate(prop);
                });
            }
        },
    },
    methods: {
        //告警类型选择
        handelType(val) {
            let cur = this.typeList.find((item) => item.value == val);
            this.$set(this.form, "type", val);
            this.typeState = cur.state;
        },
        getVal(row) {
            let { type, lower, upper, value,throttle,label,rules } = row;
            label=label||'指标值';
            let curData = this.typeList.find(item => item.value == type);
            if(throttle){
                curData = this.typeList1.find(item => item.value == type);
            }
            if(throttle){
                curData = this.typeList1.find(item => item.value == type);
            }
            if(rules){
                curData = this.typeList2.find(item => item.value == type);
            }
            if (curData.state == 1) {
                return curData.label + value
            }
            if (curData.state == 2) {
                return curData.label + (throttle?throttle:upper)
            }
            if (curData.state == 3) {
                return curData.label + (throttle?throttle:lower)
            }
            if (type == 'ltgt') {
                return lower + '<'+label+'<' + upper
            }
            if (type == 'ltegt') {
                return lower + '<'+label+'<=' + upper
            }
            if (type == 'ltgte') {
                return lower + '<='+label+'<' + upper
            }
            if (type == 'ltegte') {
                return lower +  '<='+label+'<=' + upper
            }

        },
        getState(type) {
            let curData = this.typeList.find(item => item.value == type);
            return curData.state;
        }

    }
}